package Reflex.私有方法;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class PrivateMethedDemo {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        //获取类，jdbc叫加载驱动
        Class stuClass = Class.forName("Reflex.类.Student");

        // 实例化
        Object stuInstance = stuClass.newInstance();

        //获取方法
        Method stuMethod = stuClass.getDeclaredMethod("privateMethod",String.class);

        //打破私有访问
        stuMethod.setAccessible(true);

        //援引
        Object invokeToReturn = stuMethod.invoke(stuInstance,"我要成为最强程序员");
        System.out.println(invokeToReturn);
    }
}
